import gcoord from "../../miniprogram_npm/gcoord/dist/gcoord";
import moreConditions from "./condtion";
import config from "./config";

Page({
  data: {
    isVip: '',
    // 当前的位置
    latitude: "",
    longitude: "",
    // 画圆
    circles: [],
    nearByList: [], // 企业后台接口信息集合
    originList: [], // 原始列表数据
    markers: [], // 企业标记点集合
    data: [],
    markerId: "",
    activeIndex: 0, // 默认的产业选择
    actionType: 1, // 默认收缩
    pageNum: 1,
    total: "", // 附近企业总数
    titleName: "", // 页面的标题
    // 当前位置
    geographicalLocation: "",
    // 搜索筛选
    serach_pro: "",
    value1: "",
    option1: [{
      text: "全部行业",
      value: "",
    }, ],
    value2: "",
    option2: [{
        text: "不限评分",
        value: "",
      },
      {
        text: "500分以下",
        value: "0-500",
      },
      {
        text: "500 - 599 分",
        value: "500-599",
      },
      {
        text: " 600 - 699 分",
        value: "600-699",
      },
      {
        text: "700 分以上",
        value: "700-10000",
      },
    ],
    // 更多
    option3: [],
    value3: "1",
    moreConditions: [],
    distance: "0.5", // 选择的距离
    scoreLowerLimit: "", // 选择的评分下限
    scoreUpperLimit: "", // 选择的评分上限
    extraObj: {}, // 额外的查询条件
    bigCon: {},
    cyyqObj: {}, // 产业园区的条件
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    swiperPos: "", //滑动swiper的位置
    lastswiperPos: "",
    swiperlistTwo: [{
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_dzxx.png",
        text: "电子信息",
        isSelect: false,
      },
      {
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_szjj.png",
        text: "数字经济",
        isSelect: false,
      },
      {
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_gdzbzz.png",
        text: "高端装备制造",
        isSelect: false,
      },
      {
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_swyx.png",
        text: "生物医药",
        isSelect: false,
      },
      {
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_jcdl.png",
        text: "集成电路",
        isSelect: false,
      },
      {
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_qclbj.png",
        text: "汽车零部件",
        isSelect: false,
      },
      {
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_xjcl.png",
        text: "先进材料",
        isSelect: false,
      },
      {
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_xz.png",
        text: "软件服务",
        isSelect: true,
      },
      {
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/zqy_swiper_two_hkht.png",
        text: "航空航天",
        isSelect: false,
      },
    ],

    swiperlistpageTwo: [{
        text: "大型企业",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page2_dxqy.png",
      },
      {
        text: "小微企业",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page2_xwqy.png",
      },

      {
        text: "瞪羚企业",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page2_dlqy.png",
      },
      {
        text: "外贸企业",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page2_wmqy.png",
      },
      {
        text: "高新技术",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page2_gxqy.png",
      },
      {
        text: "科技型",
        text2: "中小企业",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page2_kjxzxqy.png",
      },
      {
        text: "政府采购",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page2_zfcg.png",
      },
      {
        text: "无贷企业",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page2_wdqy.png",
      },
      {
        text: "高成长",
        text2: "创新型企业",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/4.png",
      },
      {
        text: "民营企业",
        text2: "100强",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/9.png",
      },
      {
        text: "民营企业",
        text2: "创新100强",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/8.png",
      },
      {
        text: "专精特新",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/10.png",
      },
      {
        text: "省级企业",
        text2: "技术中心",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/mapDetail/16.png",
      },
      {
        text: "民营",
        text2: "科技企业",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/mapDetail/15.png",
      },
      {
        text: "全量搜索",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/5.png",
      },
    ],
    swiperlistpageThree: [{
        text: "用工增长",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_yonggongzz.png",
      },
      {
        text: "用水增长",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_ysqy.png",
      },

      {
        text: "用电增长",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_ydzz.png",
      },
      {
        text: "用气增长",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_yqzz.png",
      },
      {
        text: "核心员工增长",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_hxygzz.png",
      },
      {
        text: "营收前30%",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_ysq30%25.png",
      },
      {
        text: "营收增长",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_yingshouzz.png",
      },
      {
        text: "纳税前30%",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_nsq30%25.png",
      },
      {
        text: "纳税增长",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_nashuizz.png",
      },
      {
        text: "净利润增长",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_jlrzz.png",
      },
      {
        text: "纳税A级",
        text2: "",
        imgSrc: " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version02/zqy_page3_nsAj.png",
      },
      {
        text: "专利增加",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/3.png",
      },
      {
        text: "进口增长",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/2.png",
      },
      {
        text: "出口增长",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/1.png",
      },
      {
        text: "环保信用评价",
        text2: "",
        imgSrc: "https://zx-1311146360.cos.ap-shanghai.myqcloud.com/Arrorney_copy/18.png",
      },
    ],
    oneActiveIndex: "",
    twoActiveIndex: "",
    threeActiveIndex: "",
    currentSwiperPage: 0,
    showSearch: false,
    searchList: [], // 查询条件
    rightInfos: [], // 右侧展示的数据
    rightTwoInfos: null, // 右侧第二列的数据
    leftKey: "", // 左侧选中的项的key值
    showSpe: false, // 控制第三列的显示和隐藏
    showDis: true,
    originListMore: [], // 原始数据
    showFx: true,
    tabLists: [{
        name: "500m",
      },
      {
        name: "1km",
      },
      {
        name: "2km",
      },
      {
        name: "3km",
      },
    ],
    activeTabIndex: 1,
    showSort1: false,
    showSort2: false,
    showSort3: false,
    sortKey1: 0,
    sortKey2: 'sort1',
    sortList1: ['500m', '1km', '2km', '3km'],
    sortList2: [],
    sortColumn: 'distance',
    sortRule: 'asc',
  },

  // 页面解析完成后执行
  onReady: function () {
    // 步骤一、常见地图实例对象
    this.mapCtx = wx.createMapContext("myMap");
  },
  onShow: function (e) {
    // console.log(e, "eeeeee");
  },
  onLoad: function (e) {
    this.setData({
      sortList2: [{
          sortColumn: 'distance',
          sortRule: 'asc',
          label: '距离由近及远',
          key: 'sort1'
        },
        {
          sortColumn: 'distance',
          sortRule: 'desc',
          label: '距离由远及近',
          key: 'sort2'
        },
        {
          sortColumn: 'creditScore',
          sortRule: 'desc',
          label: '评分从高到低',
          key: 'sort3'
        },
        {
          sortColumn: 'creditScore',
          sortRule: 'asc',
          label: '评分从低到高',
          key: 'sort4'
        },
        {
          sortColumn: 'esdate',
          sortRule: 'asc',
          label: '成立日期由远及近',
          key: 'sort5'
        },
        {
          sortColumn: 'esdate',
          sortRule: 'desc',
          label: '成立日期由近及远',
          key: 'sort6'
        },
      ],
    })
    const that = this;
    this.initYqInfos();
    getApp().globalData.getLocation({
      type: "gcj02",
      success(res) {
        that.setData({
          longitude: that.transMarker([res.longitude, res.latitude])[0],
          latitude: that.transMarker([res.latitude, res.latitude])[1],
        });
        // that.getLocationNow(res);
        that.initInfos(true);
      },
    });
   

  },


  async initYqInfos() {
    // 获取园区信息
    const {
      data
    } = await getApp().globalData.request(
      "/map/queryIndustrialParks", {
        needToken: true
      },
      "POST"
    );
    console.log(data, "data");
    if (data) {
      data.forEach((der) => {
        der.parks.forEach((dew) => {
          dew.key = "userLng";
          dew.label = dew.name;
          dew.parentLabel = der.region;
          dew.value = dew.coordinate;
        });
      });
      const searchList = config.getSearchList();
      console.log(searchList, 'searchListsearchList')
      const cyyq = searchList.find((val) => val.key === "cyyq");
      // cyyq.children.showLabel = data[0].region
      data.forEach((pre) => {
        cyyq.children.push({
          key: "",
          value: "",
          label: pre.region,
          showLabel: "",
          children: pre.parks,
        });
      });
      const originListMore = JSON.parse(JSON.stringify(searchList));
      console.log(originListMore, "originListMore");
      this.setData({
        searchList: searchList,
        originListMore: originListMore,
      });
    }

  },
  swiperdanimationfinish(e) {
    console.log("松开");
    console.log(e);
    this.setData({
      currentSwiperPage: e.detail.current,
    });
  },
  // 滑动底部
  onReachBottom: function () {

    this.scrollBottom();
  },
  /**
   * methods
   */
  async showPopup() {
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    this.setData({
      showSearch: true,
    });
  },

  onClose() {
    this.setData({
      showSearch: false,
    });
  },
  // 排序1
  async goSort1() {
    // getApp().globalData.request(
    //   '/user/getTrialUserUsageCount', {},
    //   "POST"
    // ).then(res => {
    //  console.log(res,'我的等级')
    // })
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    this.setData({
      showSort1: true
    })
  },
  onClose1() {
    this.setData({
      showSort1: false,
    });
  },
  selectSort1(e) {
    const name = e.currentTarget.dataset.name
    const index = e.currentTarget.dataset.index
    this.setData({
      sortKey1: index
    })
    this.onClose1()
    this.goSearch(name)
  },
  // 排序2
  async goSort2() {
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    this.setData({
      showSort2: true
    })
  },
  onClose2() {
    this.setData({
      showSort2: false,
    });
  },
  selectSort2(e) {
    const key = e.currentTarget.dataset.key
    const sortColumn = e.currentTarget.dataset.sortcolumn
    const sortRule = e.currentTarget.dataset.sortrule
    this.setData({
      sortKey2: key,
      sortColumn: sortColumn,
      sortRule: sortRule,
      showSort2: false,
    })
    this.clickCy();
  },

  // 初始化数据
  async initInfos(needToken = false) {
    // 获取周边企业的坐标
    await this.getNearByInfos(needToken);
  },
  // selectLeft (e) {
  //   const key = e.currentTarget.dataset.key
  //   const rightInfos = this.data.searchList.find(val => val.key === key)
  //   console.log(rightInfos.children[0].children[0], 'rightInfos')
  //   if (rightInfos.children[0].children[0].children && rightInfos.children[0].children[0].children.length > 0) {
  //     this.setData({
  //       showSpe: true,
  //     })
  //     if (!this.data.rightTwoInfos) {
  //       this.setData({
  //         rightTwoInfos: rightInfos.children[0].children[0]
  //       })
  //     }
  //   } else {
  //     this.setData({
  //       showSpe: false
  //     })
  //     // if (!rightInfos.children[0].children) {
  //     //   this.setData({
  //     //     rightTwoInfos: null
  //     //   })
  //     // }
  //   }
  //   this.setData({
  //     rightInfos: rightInfos.children,
  //     leftKey: key
  //   })
  // },
  selectLeft(e) {
    const obj = e.currentTarget.dataset;
    const leftObj = this.data.searchList.find((val) => val.key === obj.key);
    leftObj.showIndex = obj.index;
    leftObj.showKey = obj.showKey;
    leftObj.showValue = obj.showValue;
    this.setData({
      searchList: this.data.searchList,
    });
  },
  selectRight(e) {
    const obj = e.currentTarget.dataset;
    const needList = JSON.parse(JSON.stringify(this.data.originListMore));
    const index = needList.findIndex((val) => val.key === obj.key);
    needList[index].showSecondaryIndex = obj.index;
    needList[index].showValue = obj.showvalue;
    this.setData({
      searchList: needList,
    });
    this.goMoreSearch();
  },
  selectOne(e) {
    const obj = e.currentTarget.dataset;
    // console.log(e, 'eee')
    const needList = JSON.parse(JSON.stringify(this.data.originListMore));
    const index = needList.findIndex((val) => val.key === obj.key);
    needList[index].showIndex = obj.index;
    needList[index].showValue = obj.showvalue;
    needList[index].showKey = obj.showkey;
    this.setData({
      searchList: needList,
    });
    this.goMoreSearch();
  },
  // selectOne (e) {
  // console.log('e', e)
  // const rightOneInfo = this.data.rightInfos.find(val => val.key === e.currentTarget.dataset.parentkey)
  // // 是否展示右侧第二列的数据
  // console.log(rightOneInfo.children[e.currentTarget.dataset.index].children, 'rightOneInfo.children[e.currentTarget.dataset.index].children')
  // if (rightOneInfo.children[e.currentTarget.dataset.index].children && rightOneInfo.children[e.currentTarget.dataset.index].children.length > 0) {
  //   this.setData({
  //     rightTwoInfos: rightOneInfo.children[e.currentTarget.dataset.index]
  //   })
  // } else {
  //   // 清空数据
  //   this.data.searchList.forEach(val => {
  //     if (!val.children[0].children[0].children) {
  //       val.children[0].showLabel = ''
  //       val.children[0].showKey = ''
  //       val.children[0].showValue = ''
  //     } else {
  //       console.log(val.children[0].children, 'val.children[0].children')
  //       val.children[0].showLabel = '吴江区'
  //       val.children[0].children.forEach(pre => {
  //         pre.showLabel = ''
  //         pre.showKey = ''
  //         pre.showValue = ''
  //       })
  //     }
  //   })
  //   this.setData({
  //     searchList: this.data.searchList,
  //     rightTwoInfos: null
  //   })
  // }
  // const rightInfo = this.data.rightInfos.find(val => val.key === e.currentTarget.dataset.parentkey)
  // rightInfo.showKey = e.currentTarget.dataset.key
  // rightInfo.showValue = e.currentTarget.dataset.value
  // rightInfo.showLabel = e.currentTarget.dataset.label
  // const leftIndex = this.data.searchList.findIndex(val => val.key === this.data.leftKey)
  // this.data.searchList[leftIndex].children = this.data.rightInfos
  // this.setData({
  //   rightInfos: this.data.rightInfos,
  //   searchList: this.data.searchList
  // })
  // console.log(this.data.rightInfos, 'rightInfos')
  // console.log(this.data.searchList, 'searchList')
  // this.goMoreSearch()
  // },
  selectTwo(e) {
    // console.log('e', e)
    // 清空数据
    this.data.searchList.forEach((val) => {
      if (!val.children[0].children[0].children) {
        val.children[0].showLabel = "";
        val.children[0].showKey = "";
      } else {
        // console.log(val.children[0].children, 'val.children[0].children')
        // val.children[0].showLabel = ''
        val.children[0].children.forEach((pre) => {
          pre.showLabel = "";
        });
      }
    });
    this.data.rightTwoInfos.showLabel = e.currentTarget.dataset.label;
    this.data.rightTwoInfos.showKey = e.currentTarget.dataset.key;
    this.data.rightTwoInfos.showValue = e.currentTarget.dataset.value;
    this.setData({
      rightTwoInfos: this.data.rightTwoInfos,
      // searchList: this.data.searchList,
    });
    this.goMoreSearch();
  },
  // 进行搜索
  goMoreSearch() {
    const Obj = {};
    this.data.searchList.forEach((pr) => {
      if (pr.showValue && pr.key === "cyyq") {
        Obj.userLng = pr.showValue.split(",")[0];
        Obj.userLat = pr.showValue.split(",")[1];
        Obj.distance = '1.0'
      } else if (pr.showValue && pr.key !== "cyyq") {
        Obj[pr.showKey] = pr.showValue;
      }
    });
    this.setData({
      cyyqObj: Obj,
      showSearch: false,
      showDis: false,
      distance: ''
    });
    // 特殊处理当前位置
    this.setData({
      showSort1: false,
      sortKey1: 999
    })
    // 特殊处理智能排序
    if (this.data.sortColumn === 'distance') {
      this.setData({
        sortColumn: '',
        sortRule: '',
        sortKey2: '',
        sortList2: [{
            sortColumn: 'creditScore',
            sortRule: 'desc',
            label: '评分从高到低',
            key: 'sort3'
          },
          {
            sortColumn: 'creditScore',
            sortRule: 'asc',
            label: '评分从低到高',
            key: 'sort4'
          },
          {
            sortColumn: 'esdate',
            sortRule: 'asc',
            label: '成立日期由远及近',
            key: 'sort5'
          },
          {
            sortColumn: 'esdate',
            sortRule: 'desc',
            label: '成立日期由近及远',
            key: 'sort6'
          }
        ]
      })
    } else {
      this.setData({
        sortList2: [{
            sortColumn: 'creditScore',
            sortRule: 'desc',
            label: '评分从高到低',
            key: 'sort3'
          },
          {
            sortColumn: 'creditScore',
            sortRule: 'asc',
            label: '评分从低到高',
            key: 'sort4'
          },
          {
            sortColumn: 'esdate',
            sortRule: 'asc',
            label: '成立日期由远及近',
            key: 'sort5'
          },
          {
            sortColumn: 'esdate',
            sortRule: 'desc',
            label: '成立日期由近及远',
            key: 'sort6'
          }
        ]
      })
    }
    this.clickCy();
  },
  // 企业搜索
  async tozhaoqiyeClick() {
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    wx.navigateTo({
      url: "/packageA/pages/homelink/zhaoqiye/zhaoqiye",
    });
  },

  // 切换地址
  tolookAddress() {
    var that = this;
    wx.chooseLocation({
      success(res) {
        that.setData({
          longitude: that.transMarker([res.longitude, res.latitude])[0],
          latitude: that.transMarker([res.latitude, res.latitude])[1],
        });
        that.getLocationNow(res);
        // that.initInfos();
        that.clickCy();
      },
      fail(res) {
        // console.log(res, "失败回调");
      },
      complete(res) {
        // console.log(res, "结束回调");
      },
    });
  },
  // page2
  async tabTuijianCy(e) {
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }

    if (this.data.twoActiveIndex === e.currentTarget.dataset.index) {
      this.setData({
        oneActiveIndex: "",
        twoActiveIndex: "",
        threeActiveIndex: "",
      });
      this.goSearch("所有");
    } else {
      this.setData({
        oneActiveIndex: "",
        twoActiveIndex: e.currentTarget.dataset.index,
        threeActiveIndex: "",
      });
      this.goSearch(e.currentTarget.dataset.itemtitle);
    }
  },
  // page2
  async tabtwoClick(e) {
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    // if (!this.data.isVip) {
    //   getApp().globalData.checkVipStatus('看周边', 'I')
    //   return false
    // }
    if (this.data.threeActiveIndex === e.currentTarget.dataset.index) {
      this.setData({
        oneActiveIndex: "",
        twoActiveIndex: "",
        threeActiveIndex: "",
      });
      this.goSearch("所有");
    } else {
      this.setData({
        oneActiveIndex: "",
        twoActiveIndex: "",
        threeActiveIndex: e.currentTarget.dataset.index,
      });
      this.goSearch(e.currentTarget.dataset.itemtitle);
    }
  },
  chooseOne(e) {
    const info = e.currentTarget.dataset;
    this.setData({
      activeTabIndex: info.index
    })
    this.goSearch(info.title);
  },
  // page1
  async tabTuijian(e) {
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    if (this.data.oneActiveIndex === e.currentTarget.dataset.index) {
      this.setData({
        oneActiveIndex: "",
        twoActiveIndex: "",
        threeActiveIndex: "",
      });
      this.goSearch("所有");
    } else {
      this.setData({
        extraObj: {},
        oneActiveIndex: e.currentTarget.dataset.index,
        twoActiveIndex: "",
        threeActiveIndex: "",
      });
      this.goSearch(e.currentTarget.dataset.itemtitle);
    }
  },
  resetMoreList() {
    const needList = JSON.parse(JSON.stringify(this.data.originListMore));
    this.setData({
      searchList: needList,
      sortList2: [{
          sortColumn: 'distance',
          sortRule: 'asc',
          label: '距离由近及远',
          key: 'sort1'
        },
        {
          sortColumn: 'distance',
          sortRule: 'desc',
          label: '距离由远及近',
          key: 'sort2'
        },
        {
          sortColumn: 'creditScore',
          sortRule: 'desc',
          label: '评分从高到低',
          key: 'sort3'
        },
        {
          sortColumn: 'creditScore',
          sortRule: 'asc',
          label: '评分从低到高',
          key: 'sort4'
        },
        {
          sortColumn: 'esdate',
          sortRule: 'asc',
          label: '成立日期由远及近',
          key: 'sort5'
        },
        {
          sortColumn: 'esdate',
          sortRule: 'desc',
          label: '成立日期由近及远',
          key: 'sort6'
        },
      ],
    })
    // 特殊处理智能排序
    if (!this.data.sortColumn) {
      this.setData({
        sortColumn: 'distance',
        sortRule: 'asc',
        sortKey2: 'sort1'
      })
    }
  },
  goSearch(item) {
    switch (item) {
      case "所有":
        console.log("所有");
        this.setData({
          extraObj: {},
        });
        this.resetMoreList();
        this.clickCy();
        break;
      case "500m":
        this.setData({
          cyyqObj: {},
          distance: "0.5",
        });
        this.resetMoreList();
        this.clickCy();
        break;
      case "1km":
        this.setData({
          cyyqObj: {},
          distance: "1.0",
        });
        this.resetMoreList();
        this.clickCy();
        break;
      case "2km":
        this.setData({
          cyyqObj: {},
          distance: "2.0",
        });
        this.resetMoreList();
        this.clickCy();
        break;
      case "3km":
        this.setData({
          cyyqObj: {},
          distance: "3.0",
        });
        this.resetMoreList();
        this.clickCy();
        break;
      case "营收500-1000万":
        const params1 = {
          businessIncomeLowerLimit: "500",
          businessIncomeUpperLimit: "1000",
        };
        this.setData({
          extraObj: params1,
        });
        this.clickCy();
        break;
      case "营收1000万以上":
        const params2 = {
          businessIncomeLowerLimit: "1000",
          businessIncomeUpperLimit: "50000",
        };
        this.setData({
          extraObj: params2,
        });
        this.clickCy();
        break;
      case "有融资需求":
        const params3 = {
          isLoan: "1",
        };
        this.setData({
          extraObj: params3,
        });
        this.clickCy();
        break;
      case "未结清信贷":
        const params4 = {
          qutstandingLoans: "1",
        };
        this.setData({
          extraObj: params4,
        });
        this.clickCy();
        break;
      case "未结清小额贷款":
        const params5 = {
          qutstandingSmallLoans: "1",
        };
        this.setData({
          extraObj: params5,
        });
        this.clickCy();
        break;
      case "纳税A级":
        const params6 = {
          taxALeavel: "1",
        };
        this.setData({
          extraObj: params6,
        });
        this.clickCy();
        break;
      case "用水企业":
        const params7 = {
          isWater: "1",
        };
        this.setData({
          extraObj: params7,
        });
        this.clickCy();
        break;
      case "用电企业":
        const params8 = {
          isElec: "1",
        };
        this.setData({
          extraObj: params8,
        });
        this.clickCy();
        break;
      case "缴纳社保":
        const params9 = {
          isSecurity: "1",
        };
        this.setData({
          extraObj: params9,
        });
        this.clickCy();
        break;
      case "缴纳公积金":
        const params10 = {
          isFund: "1",
        };
        this.setData({
          extraObj: params10,
        });
        this.clickCy();
        break;
      case "电子信息":
        const params12 = {
          keyIndustries: "电子信息产业",
        };
        this.setData({
          extraObj: params12,
        });
        this.clickCy();
        break;
      case "数字经济":
        const params13 = {
          keyIndustries: "数字经济产业",
        };
        this.setData({
          extraObj: params13,
        });
        this.clickCy();
        break;
      case "高端装备制造":
        const params14 = {
          keyIndustries: "高端装备制造产业",
        };
        this.setData({
          extraObj: params14,
        });
        this.clickCy();
        break;
      case "生物医药":
        const params15 = {
          keyIndustries: "生物医药产业",
        };
        this.setData({
          extraObj: params15,
        });
        this.clickCy();
        break;
      case "集成电路":
        const params16 = {
          keyIndustries: "集成电路产业",
        };
        this.setData({
          extraObj: params16,
        });
        this.clickCy();
        break;
      case "汽车零部件":
        const params17 = {
          keyIndustries: "汽车零部件产业",
        };
        this.setData({
          extraObj: params17,
        });
        this.clickCy();
        break;
      case "先进材料":
        const params18 = {
          keyIndustries: "先进材料产业",
        };
        this.setData({
          extraObj: params18,
        });
        this.clickCy();
        break;
      case "软件服务":
        const params19 = {
          keyIndustries: "软件服务产业",
        };
        this.setData({
          extraObj: params19,
        });
        this.clickCy();
        break;
      case "航空航天":
        const params20 = {
          keyIndustries: "航空航天产业",
        };
        this.setData({
          extraObj: params20,
        });
        this.clickCy();
        break;
      case "大型企业":
        const params21 = {
          bigCorp: "1",
        };
        this.setData({
          extraObj: params21,
        });
        this.clickCy();
        break;
      case "小微企业":
        const params22 = {
          smallAndMicroCorp: "1",
        };
        this.setData({
          extraObj: params22,
        });
        this.clickCy();
        break;
      case "瞪羚企业":
        const params23 = {
          isGoats: "1",
        };
        this.setData({
          extraObj: params23,
        });
        this.clickCy();
        break;
      case "外贸企业":
        const params24 = {
          isTrade: "1",
        };
        this.setData({
          extraObj: params24,
        });
        this.clickCy();
        break;
      case "高新技术":
        const params25 = {
          isHightech: "1",
        };
        this.setData({
          extraObj: params25,
        });
        this.clickCy();
        break;
      case "科技型中小企业":
        const params26 = {
          technology: "1",
        };
        this.setData({
          extraObj: params26,
        });
        this.clickCy();
        break;
      case "政府采购":
        const params27 = {
          isGovpur: "1",
        };
        this.setData({
          extraObj: params27,
        });
        this.clickCy();
        break;
      case "无贷企业":
        const params28 = {
          isLoan: "0",
        };
        this.setData({
          extraObj: params28,
        });
        this.clickCy();
        break;
      case "用工增长":
        const params29 = {
          laborTrend: "1",
        };
        this.setData({
          extraObj: params29,
        });
        this.clickCy();
        break;
      case "用水增长":
        const params30 = {
          waterTrend: "1",
        };
        this.setData({
          extraObj: params30,
        });
        this.clickCy();
        break;
      case "用电增长":
        const params31 = {
          electricTrend: "1",
        };
        this.setData({
          extraObj: params31,
        });
        this.clickCy();
        break;
      case "用气增长":
        const params32 = {
          gasTrend: "1",
        };
        this.setData({
          extraObj: params32,
        });
        this.clickCy();
        break;
      case "核心员工增长":
        const params33 = {
          corePersonTrend: "1",
        };
        this.setData({
          extraObj: params33,
        });
        this.clickCy();
        break;
      case "营收前30%":
        const params34 = {
          revenueLevel: "30",
        };
        this.setData({
          extraObj: params34,
        });
        this.clickCy();
        break;
      case "营收增长":
        const params35 = {
          revenueTrend: "1",
        };
        this.setData({
          extraObj: params35,
        });
        this.clickCy();
        break;
      case "纳税前30%":
        const params36 = {
          taxLevel: "30",
        };
        this.setData({
          extraObj: params36,
        });
        this.clickCy();
        break;
      case "纳税增长":
        const params37 = {
          taxTrend: "1",
        };
        this.setData({
          extraObj: params37,
        });
        this.clickCy();
        break;
      case "净利润增长":
        const params38 = {
          netProfitsTrend: "1",
        };
        this.setData({
          extraObj: params38,
        });
        this.clickCy();
        break;
      case "纳税A级":
        const params39 = {
          taxALeavel: "1",
        };
        this.setData({
          extraObj: params39,
        });
        this.clickCy();
        break;
      case "专利增加":
        const params40 = {
          patentTrend: "1",
        };
        this.setData({
          extraObj: params40,
        });
        this.clickCy();
        break;
      case "进口增长":
        const params41 = {
          importTrend: "1",
        };
        this.setData({
          extraObj: params41,
        });
        this.clickCy();
        break;
      case "出口增长":
        const params42 = {
          exportTrend: "1",
        };
        this.setData({
          extraObj: params42,
        });
        this.clickCy();
        break;
      case "高成长创新型企业":
        const params43 = {
          isUnicorn: "1",
        };
        this.setData({
          extraObj: params43,
        });
        this.clickCy();
        break;
      case "民营企业100强":
        const saveInfos1 = {
          istophrd: 1
        }
        wx.navigateTo({
          url: `/pages/companyList/companyList?selectedObj=${JSON.stringify(saveInfos1)}&type=${1}`
        })
        break;
      case "民营企业创新100强":
        const saveInfos2 = {
          istopinno: 1
        }
        wx.navigateTo({
          url: `/pages/companyList/companyList?selectedObj=${JSON.stringify(saveInfos2)}&type=${1}`
        })
        break;
      case "专精特新":
        const saveInfos3 = {
          issrdi: 1
        }
        wx.navigateTo({
          url: `/pages/companyList/companyList?selectedObj=${JSON.stringify(saveInfos3)}&type=${1}`
        })
        break;
      case "省级企业技术中心":
        const saveInfos4 = {
          isTechCenter: 1
        }
        wx.navigateTo({
          url: `/pages/companyList/companyList?selectedObj=${JSON.stringify(saveInfos4)}&type=${1}&nameType=2`
        })
        break;
      case "民营科技企业":
        const saveInfos5 = {
          isPrivate: 1
        }
        wx.navigateTo({
          url: `/pages/companyList/companyList?selectedObj=${JSON.stringify(saveInfos5)}&type=${1}`
        })
        break;
      case "全量搜索":
        console.log("全量搜索");
        wx.navigateTo({
          url: `/sun_chaifen/advancedSearch/advancedSearch?type=${1}`,
        });
        break;
      case "高级筛选":
        console.log("高级筛选");
        wx.navigateTo({
          url: `/sun_chaifen/advancedSearch/advancedSearch?type=${2}`,
        });
        break;
      case "环保信用评价":
        console.log("环保信用评价");
        wx.navigateTo({
          url: `../../sub_zhaoqiye/page1/page1?type=${1}`
        })
        break;
      default:
        break;
    }
  },

  // 获取附近企业的坐标
  async getNearByInfos(needToken = fasle) {
    const params = {
      userLng: this.data.longitude,
      userLat: this.data.latitude,
      pageBO: {
        pageSize: 10,
        pageNum: this.data.pageNum,
      },
      distance: this.data.distance,
      sortColumn: this.data.sortColumn,
      sortRule: this.data.sortRule,
      needToken: needToken
    };
    if (this.data.cyyqObj && this.data.cyyqObj.region) {
      this.setData({
        showDis: false,
        distance: ''
      });
      delete params.userLng;
      delete params.userLat;
      delete params.distance;
    }
    var condtion = Object.assign(
      params,
      this.data.extraObj,
      this.data.cyyqObj,
    );
    wx.showLoading({
      title: "加载中",
    });
    console.log(condtion, "附近企业查询条件22");
    const {
      list,
      total
    } = await getApp().globalData.request(
      "/map/lookAroundV2",
      condtion,
      "POST"
    );
    wx.hideLoading();
    // 原始列表数据
    console.log(this.data.originList.concat(list),'列表数据')
    this.setData({
      originList: this.data.originList.concat(list),
      total: total,
    });

  },

  // 获取当前地理位置
  getLocationNow(info) {
    getApp()
      .globalData.request(
        "/map/inverseGeocode", {
          lat: this.transMarker([info.longitude, info.latitude])[1],
          lng: this.transMarker([info.longitude, info.latitude])[0],
          needToken: true
        },
        "POST"
      )
      .then((res) => {
        console.log(res);
        const rstObj = res;
        console.log();
        this.setData({
          geographicalLocation: rstObj.data.replace("苏州市苏州", "苏州市"),
        });
      });
  },

  // 跳转企业详情或者企业列表
  markerCalloutTap(e) {
    console.log(e.markerId, "e");
    if (this.data.nearByList[e.markerId].length > 1) {
      // 跳转到列表页面
      wx.navigateTo({
        url: `../../packageB/pages/businesses/businesses?businesses=${JSON.stringify(
          this.data.nearByList[e.markerId]
        )}`,
      });
    } else {
      // 跳转到详情页面
      wx.navigateTo({
        url: `../Company/Company?corpKey=${this.data.nearByList[e.markerId][0].corpKey
          }`,
      });
    }
  },
  toprodetail(e) {
    console.log(e.currentTarget.dataset.proitem.corpKey);
    // wx.setStorage({
    //   key: "Company",
    //   data: e.currentTarget.dataset.proitem
    // })
    wx.navigateTo({
      url: "/pages/Company/Company?corpKey=" +
        e.currentTarget.dataset.proitem.corpKey,
    });
  },
  // 滑动底部加载更多
  async scrollBottom() {
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为VIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    // this.onBottom();

    this.setData({
      pageNum: ++this.data.pageNum,
    });
    this.initInfos();
  },

  // 产业切换
  clickCy() {
    // 切换后重置分页参数和列表原始数组
    this.setData({
      pageNum: 1,
      originList: [],
    });
    this.initInfos();
  },
  // 坐标系转化
  transMarker(item) {
    const resae = gcoord.transform(
      [item[0], item[1]],
      gcoord.GCJ02, // 当前坐标系
      gcoord.BD09 // 目标坐标系
    );
    return resae;
  },
  // 返回到当前定位视窗
  locationBack() {
    this.mapCtx.moveToLocation();
  },
  toprodetail(e) {
    let distance = "";
    if (this.data.showDis) {
      distance = e.detail.distance;
    }
    wx.navigateTo({
      url: `/pages/mapDetail/mapDetail?corpKey=${e.detail.corpKey}&latitude=${e.detail.latitude}&longitude=${e.detail.longitude}&distance=${distance}`,
    });
  },
});